#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

class Point
{
public:
    double x;
    double y;
    Point(double x, double y) : x(x), y(y) {}
};

//sort()的比较函数，按点的x坐标升序排列
bool xorder(const Point &p1, const Point &p2)
{
    return p1.x < p2.x;
}
//sort()的比较函数，按点的y坐标升序排列
bool yorder(const Point &p1, const Point &p2)
{
    return p1.y < p2.y;
}

double distance(Point &p1, Point &p2)
{
    return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}

double closest_pair(std::vector<Point> &points, int l, int r)
{
    if (r - l == 1)
        return distance(points[l], points[r]);
    
    if (r - l == 2)
    {
        double d1 = distance(points[l], points[l + 1]);
        double d2 = distance(points[l], points[l + 2]);
        double d3 = distance(points[l + 1], points[l + 2]);
        return fmin(d1, fmin(d2, d3));
    }
    int mid = (l + r) / 2;
    double d1 = closest_pair(points, l, mid);
    double d2 = closest_pair(points, mid + 1, r);
    double d = fmin(d1, d2);

    std::vector<Point> strip_points;
    for (int i = l; i < r; i++)
    {
        if (fabs(points[i].x - points[mid].x) <= d)
            strip_points.push_back(points[i]);
    }

    //将所有的点按照y坐标的位置升序排序
    sort(strip_points.begin(), strip_points.end(), yorder);
    
    for (int i = 0; i < strip_points.size(); i++)
    {
        for (int j = i + 1; j < strip_points.size() && fabs(strip_points[i].y - strip_points[j].y); j++)
        {
            double d1 = distance(strip_points[i], strip_points[j]);
            d = d1 < d ? d1 : d;
        }
    }
    return d;
}

int main()
{
    using namespace std;
    vector<Point> points;
    points.push_back(Point(-2.0, 0));
    points.push_back(Point(-1.0, 1.0));
    points.push_back(Point(2.5, 3.0));
    points.push_back(Point(-2.0, -2.5));
    points.push_back(Point(1.5, 1.0));
    points.push_back(Point(3.0, -1.0));
    points.push_back(Point(4.0, -2));
    points.push_back(Point(0, 1.5));

    //将所有的点按照x坐标的位置升序排序
    sort(points.begin(), points.end(), xorder);

    cout << closest_pair(points, 0, 6) << endl;

}